﻿package com.msjt.dao;

import java.util.List;

import com.msjt.base.BaseDAO;
import com.msjt.entity.Video;
/**
 * name:VideoDAO
 * function:视频模块
 * author: kw
 * time:2013.8.27
 * updateTime:2013.8.28
 */
public class VideoDAO extends BaseDAO {
	//得到Video的记录数
	public Integer getVideoCount(){
		String hql="select count(v.videoId) from Video as v";
		return this.getTotalCount(hql, null);
	}
	//主页面加载视频地址，最后上传的视频将显示在主页
	public Video getVideoIndex(){
		String hql="select v from Video as v order by v.videoDate";
		@SuppressWarnings("unchecked")
		List<Video> videoList=(List<Video>) this.searchByPage(hql, null, 1, 1);
		if(videoList.size()!=0){
			return videoList.get(0);
		}
		return null;
	}
	//前台后台查看视频列表，只加载ID，视频描述，日期，视频在点开后才加载
	@SuppressWarnings("unchecked")
	public List<Video> getVdeoByPage(int pageIndex,int pageSize){
		String hql="select new Video(v.videoId,v.videoDesc,v.videoDate) from Video as v order by v.videoDate desc";
		return (List<Video>) this.searchByPage(hql, null, pageIndex, pageSize);
	}
	//新上传视频
	public boolean addVideo(Video video){
		return this.save(video);
	}
	//修改视频信息
	public boolean updateVideo(Video video){
		return this.saveOrUpdate(video);
	}
	//删除视频
	public boolean deleteVideo(Video video){
		return this.deleteById(video.getVideoId());
	}
	//根据ID得到视频的详细信息
	public Video getOneVideo(Video video){
		return (Video) this.findById(video.getVideoId());
	}
	//批量删除时得到路径
	@SuppressWarnings("unchecked")
	public List<String> getVideoPath(String idString){
		String hql="select video.videoPath from Video as video where video.videoId in ("+idString+")";
		return (List<String>) this.searchByHQL(hql, null);
	}
	/**
	 * 批量删除
	 * @param idString id的字符串，用“,”号隔开
	 * @return
	 */
	public boolean deleteMore(String idString){
		String hql="delete Video as video where video.videoId in ("+idString+")";
		return this.updateByHql(hql, null);
	}
}
